#!/bin/bash
# TEST SUITE FOR TASK 1 FROM MILESTONE 04
# Set-up: {1,2} middle man, {1,2} postgresql server, {0.1, 0.01} scaling factor, 81 clients
# Purpose: Solve task 1

# CONFIGURATION BEGINS HERE

# the folder where results should be stored (relative to home)
results_folder='task2'

# MUST BE AT LEAST MIDDLE MEN
machine1='dryad14.inf.ethz.ch'

# MUST BE AT LEAST SERVERS
machine2='dryad11.inf.ethz.ch'
machine3='dryad12.inf.ethz.ch'
machine4='dryad13.inf.ethz.ch'

# !!!!ATTENTION!!!! --- DIFFERENT DURATION FOR 0.01::: SEE LOWER
# DURATION IN MINUTES
# duration=40

# Duration is now looked up according to the name of the database
dura[1]=40
dura[2]=12
name[1]='01'
name[2]='001'

# AUTOMATIC ITERATION BEGINS HERE
if [ ! -d $results_folder ]; then
	mkdir $results_folder
fi

if [ ! -d /local/group3705 ]; then
	mkdir /local/group3705
fi

for DBnb in 2 1
do

	for C in 1 3 9 27 81
	do
		
		L=100
		duration=${dura[$DBnb]}
		DB=${name[$DBnb]}
		# 8 workers per MM, 8 in total, 8 per database
		P=3
		M=24
		out_file_path="$results_folder/mm1_ss3_f"$DB"_c"$C"_p"$P"_l"$L"_m"$M".raw"
		if [ ! -f $out_file_path ]; then
			middle_man_config="{{middle_man:$machine1};{{P:$P},{L:$L},{M:$M},{db_database:tpch$DB},{db_host:$machine2},{db_host:$machine3},{db_host:$machine4}}}"
			args="$C $duration $out_file_path 1 $middle_man_config"
			./client.sh $args
			# 1
		else
			echo "===========SKIPPING======== $out_file_path"
		fi

	done
done